package com.anjbo.controller.loan;

import com.anjbo.aspect.ResultWrapped;
import com.anjbo.bean.loan.ChangLoanDto;
import com.anjbo.bean.loan.RedMortgageDto;
import com.anjbo.exception.ResponseException;
import com.anjbo.service.loan.ChangLoanService;
import com.anjbo.service.loan.RedMortgageService;
import com.anjbo.utils.ConfigUtil;
import com.anjbo.utils.UidUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.List;

/**
 * Created by Administrator on 2017/6/29.
 */
@Controller
@RequestMapping(value = "/app/loan/chang")
public class ChangLoanController {

    @Autowired
    private ChangLoanService changLoanService;

    @RequestMapping("/insert")
    @ResponseBody
    @ResultWrapped
    public Object insert(@RequestBody ChangLoanDto changLoanDto) {

        int changloan_times_limit = ConfigUtil.getIntegerValue("changloan_times_limit");
        if (changLoanService.submitTimesToday(changLoanDto.getUid()) > (changloan_times_limit - 1)) {
            throw new ResponseException("畅贷每天只能申请三次");
        }
        changLoanDto.setOrderNo(UidUtil.generateOrderId());
        changLoanDto.setProgressId("200");
        changLoanDto.setProgressName("订单已提交");
        changLoanDto.setCreateTime(new Date());
        int insert = changLoanService.insert(changLoanDto);
        return insert;
    }
}
